#!/usr/bin/env bash

envoy_version="1.30.4"

set -e -u -x
source ./tasks/helpers.sh

image="envoyproxy/envoy-distroless"

task_working_dir

if [ ! -f "_persist/downloads/envoy-${envoy_version}-${TARGETARCH}.tar" ]; then
  mkdir -p _persist/downloads
  PATH="$DEV_PATH" crane export --platform "linux/${TARGETARCH}" "${image}:v${envoy_version}" "_persist/downloads/envoy-${envoy_version}-${TARGETARCH}.tar"
fi

tar -xof "_persist/downloads/envoy-${envoy_version}-${TARGETARCH}.tar" usr/local/bin/envoy

install -D -m 755 usr/local/bin/envoy "$STAGE_EMBEDDED_DIR/bin/envoy"
chrpath -d "$STAGE_EMBEDDED_DIR/bin/envoy"

stamp
